
;(function(window, document){

	var Node = function(key, value){
		return {
			key: key,
			data: value,
			next: null
		};
	};

	var DoubleEndLinkList = function(){
		this._head = null;
		this._tail = null;
	};
	DoubleEndLinkList.prototype={
		constructor: DoubleEndLinkList,
		prepend: function(pKey, pValue){
			var node = Node(pKey, pValue);
			if( this.isEmpty() ){
				this._tail = node;
			}
			node.next = this._head;
			this._head = node;
		},
		append: function(pKey, pValue){
			var node = Node(pKey, pValue);
			if( this.isEmpty() ){
				this._head = this._tail = node;
			}else{
				this._tail.next = node;
				this._tail = node;
			}
		},
		insertAfter: function(pTargetKey, pKey, pValue){
			var newNode = Node(pKey, pValue);
			var node = this._head;
			if( this.isEmpty() ){
				this._head = this._tail = node;
				return;
			}
			while(node != null ){
				if( node.key == pTargetKey ){
					newNode.next = node.next;
					node.next = newNode;
					if( newNode.next == null ) this._tail = newNode;
					break;
				}
				node = node.next;
			}
		},
		deleteHead: function(){
			this._head = this._head.next;
			if( this._head == null ) this._tail = null;
		},
		getItem: function(pKey){
			var node = this._head;
			while(node != null){
				if( node.key == pKey ) return node.data;
				node = node.next;
			}
			return null;
		},
		isEmpty: function(){
			return this._head == null;
		},
		toString: function(){
			var str = '[',
				node = this._head;
			while(node != null){
				str += node.key + '-->';
				node = node.next;
			}
			str += 'null]';
			return str;
		}
	};

	window.DoubleEndLinkList = DoubleEndLinkList;

})(window, document);